//three
define('threeJs',['jquery'],function($){
    var three={
        init:function(){
            console.log("333333333")
            var th1="<div class='th1'><span id='th1-span1'>启用</span> | <span id='th1-span2'>禁用</span></div>";
            var th2="<div class='th2' style='color:#81a3f0;cursor: pointer;'><span id='th2-span1'>编辑</span> | <span id='th2-span2'>删除</span></div>";
            var that;
            require(['domReady!','requireCss!'+'oneCss','jquery','threeJs'],function(dom,thcss,jq,three){
                //this.init();
                jq.ajax({
                    url:"https://zhusirs.gitee.io/Houtai/json/three.json",
                    type:"POST",
                    dataType:"json",
                    success: function (data) {
                        //console.table(data);
                        $.each(data, function (i, v) {
                            $(".th-tbody").append(`<tr><td>${v.id}</td><td>${v.title}</td><td>${v.url}</td><td>${th1}</td><td>${th2}</td></tr>`);
                        });
                    //    span的方法
                        $(".th-tbody").on("click","#th1-span2",function(){
                            if($(this).text() == "启用"){
                                $(this).text("禁用").siblings().text("启用").parents("tr").css("background","");
                                return false;
                            }
                            $(this).text("启用").siblings().text("禁用").parents("tr").css("background","#ccc");
                        }).on("click","#th2-span1",function(){
                            $(".o-footer").show();

                            //    点击编辑更换文字
                            $("table").on("click","td span:first-child",function(){
                                that=this;
                                $(".o-footer").find("dt:nth-child(1) input").val($(this).parents("tr").find("td:nth-child(2)").text());
                                $(".o-footer").find("dt:nth-child(2) input").val($(this).parents("tr").find("td:nth-child(3)").text());
                                if($(".o-footer").find("dt:nth-child(1) input").val() == " " || $(".o-footer").find("dt:nth-child(1) input").val() == ""){
                                    $(".o-footer").find("dt:nth-child(1) input").val("");
                                    //$(this).css({background:"red"})
                                }
                                setTimeout(function(){
                                    $(".o-footer").show();
                                },100);

                            });
                            $(".o-footer>p").on("click",function(){
                                //console.log(that)
                                $(that).parents("tr").find("td:nth-child(2)").text($(this).prev().find("dt:nth-child(1) input").val());
                                $(that).parents("tr").find("td:nth-child(3)").text($(this).prev().find("dt:nth-child(2) input").val());
                                $(this).next().show();
                            });
                            $(".o-fanhui").click(function(){
                                $(".o-footer").hide()
                            });
                            $(".hisdiv").click(function(){
                                $(this).parents(".o-open,.o-footer").hide();
                            });
                            $(".op-close").click(function(){
                                $(this).parents(".o-open").hide();
                            });
                        }).on("click","#th2-span2",function(){
                            if(window.confirm("确定删除？") == true){
                                $(this).parents("tr").remove();
                            }
                        })

                    },
                    error: function () {
                        console.log("数据加载失败");
                    }
                });
            });


        }
    };
    return three;
});
